class Point {
  /** @type {Number} */
  vx;
  /** @type {Number} */
  vy;

  /**
   *  x,y构造
   * @param {Number} x
   * @param {Number} y
   */
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
  /**
   *  欧式距离
   * @param {Point} point1
   * @param {Point} point2
   */
  static len(point1, point2) {

    var len = Math.sqrt((point1.x - point2.x) * (point1.x - point2.x) + (point1.y - point2.y) * (point1.y - point2.y)
    );
    return len;
  }

  /**
   * 
   * @param {{x:number,y:number}[]} ps 
   */
  static countCenter(ps) {
    var sumx = 0, sumy = 0;
    ps.forEach(v => {
      sumx += v.x;
      sumy += v.y;
    })
    return { x: sumx / ps.length, y: sumy / ps.length }
  }
  /**
   * 检查对象格式
   * @param {Point} obj
   */
  static check(obj) {
    return obj && obj.x && obj.y;
  }

  /**
   * 
   * @param {Point[]} points 
   */
  static sumV(points) {
    var sv = 0;
    for (let index = 0, len = points.length; index < len; index++) {
      // const element = points[index];
      sv += (points[index].vx ** 2 + points[index].vy ** 2) ** 0.5
    }
    return sv;
  }
}
module.exports = { Point }
